package com.itm.lqm.servlets.student;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.itm.lqm.entity.Student;
import com.itm.lqm.service.StudentService;

/**
 * Servlet implementation class ManagerAddBook
 */
@WebServlet("/addStudent")
public class addStudent extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public addStudent() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取添加页面的请求参数，然后调用业务逻辑层对象，实现最终修改
				request.setCharacterEncoding("UTF-8");
				response.setCharacterEncoding("UTF-8");
				response.setContentType("text/html; charset=UTF-8");
				

				String si = request.getParameter("sid");
				int  sid= Integer.parseInt(si);
				String sno =request.getParameter("sno");
				String sname =request.getParameter("sname");
				String clas = request.getParameter("clas");
				String sex = request.getParameter("sex");
				String major = request.getParameter("major");
				
				
				Student s= new Student(sid,sno, sname, clas,sex,major);
				StudentService ss=new StudentService();
				boolean result=ss.addStudent(s);
				System.out.println(s);
				System.out.println(result);
				if(result){
					request.getRequestDispatcher("findAllStudent").forward(request, response);
				}else{
					response.sendRedirect("add.jsp");
				}
				
	}

}
